home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / VideoToolBox Folder / Utilities / Quick3 / LogLikelihood.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-23  |  974 b   |  41 lines  |  [TEXT/KAHL]

  1. /*
  2. LogLikelihood.c
  3. Copyright (c) 1990 Denis G. Pelli
  4. 4/7/90 
  5. Calculate log likelihood of the data for a given psychometric function.
  6. If the psychometric function indicates that the parameters are out of bounds,
  7. then LogLikelihood() returns the lowest possible log likelihood, minus infinity. 
  8. If your machine doesn't deal in infinities, then replace 1.0/0.0 by DBL_MAX in
  9. the definition of INF.
  10.  
  11. The third argument is a pointer to a psychometric function, e.g. Weibull.c
  12.  
  13. HISTORY:
  14. 8/24/91 dgp cosmetic
  15. */
  16. #include "Quick3.h"
  17.  
  18. #define INF (1.0/0.0)
  19.  
  20. double LogLikelihood(dataRecord *data,paramRecord *params,
  21.     PsychometricFunctionPtr PsychFun)
  22. {
  23.     double LL,p;
  24.     long n;
  25.     int i;
  26.     contrastRecord *cPtr;
  27.  
  28.     LL=0.0;
  29.     for(i=0;i<data->contrasts;i++){
  30.         cPtr=&data->c[i];
  31.         p = (*PsychFun)(cPtr->contrast, params);
  32.         if(p==ILLEGAL_PARAMETERS)return -INF;
  33.         n=cPtr->correct;
  34.         if(n>0L) LL += n*log(p);
  35.         n=cPtr->trials - cPtr->correct;
  36.         if(n>0L) LL += n*log(1.0-p);
  37.     }
  38.     return LL;
  39. }
  40.  
  41.